"""
Hongyu (Vicky) Ye 
04/10/2021
Section #03
part4：Pokemon Center Database

"""
#part4a
# Pokemon lists
pokemon_names = ['charmander', 'squirtle', 'bulbasaur', 'gyrados']
pokemon_amounts = [3, 2, 5, 1]
pokemon_fees = [100, 50, 25,1000]
pokemon_types = [['fire'], ['water'], ['grass'], ['water', 'flying']]
valid_pokemon_types = ['bug', 'dark', 'dragon', 'electric', 'fairy', 'fighting', 'fire', 'flying', 'ghost', 'grass', 'ground', 'ice', 'normal', 'poison', 'psychic', 'rock', 'steel', 'water']

while True:
    print("Welcome to the Pokemon Center!")
    s_q = input("(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: ")
    lc_s_q = s_q.lower()

    if lc_s_q == "a":
        new_name = input("Enter name of new pokemon: ")
        lc_new_name = new_name.lower()
        if lc_new_name in pokemon_names:
            print("Duplicate name, add operation cancelled\n")
            continue
        else:
            pokemon_names.append(lc_new_name)
        while True:
            adding_num = int(input("How many of these Pokemon are you adding? "))
            if adding_num <= 0:
                print("Invalid, please try again")
            else:
                pokemon_amounts.append(adding_num)
                break
            
        while True:
            adoption_fee = float(input("What is the adoption fee for this Pokemon? "))
            if adoption_fee <= 0:
                print("Invalid, please try again")
            else:
                pokemon_fees.append(adoption_fee)
                print("Next you will be prompted to enter the 'types' for this Pokemon.  Pokemon can have multiple types. Type 'help' to view all possible Pokemon types, and type 'end' to stop entering types. You must enter at least one valid 'type'")
                break
        dupcheck = []
        while True:
            types = input("What type of Pokemon is this? ")
            lc_types = types.lower()
            if lc_types == "help":
                for valid_type in valid_pokemon_types:         
                    print("*", valid_type)
            elif lc_types == "end":
                pokemon_types.append(dupcheck)
                print("Pokemon added!")
                break 
            elif lc_types not in valid_pokemon_types:
                print("This is not a valid type, please try again")
            elif lc_types in dupcheck:
                print("Duplicate type")
            elif lc_types in valid_pokemon_types:
                print("Type", types, "applied")
                dupcheck.append(lc_types)     
        print()

    elif lc_s_q == "r":
        remove_name = input("Enter name of Pokemon to remove: ")
        lc_remove_name = remove_name.lower()
        if lc_remove_name not in pokemon_names:
            print("Pokemon not found, cannot remove\n")
            continue
        else:
            print("Pokemon removed")
            location = pokemon_names.index(lc_remove_name)
            pokemon_names.remove(pokemon_names[location])
            pokemon_amounts.remove(pokemon_amounts[location])
            pokemon_fees.remove(pokemon_fees[location])
        
        print()

    elif lc_s_q == "e":
        highest_price = max(pokemon_fees)
        lowest_price = min(pokemon_fees)
        temp1 = pokemon_fees.index(highest_price)
        temp2 = pokemon_fees.index(lowest_price)
        highest_name = pokemon_names[temp1]
        lowest_name = pokemon_names[temp2]
        counter = 0
        for i in range(0, len(pokemon_names)):
            counter += (pokemon_fees[i] * pokemon_amounts[i])
        print("Highest priced Pokemon:", highest_name.captialize(), "@ $" + format(highest_price, ",.2f"), "per Pokemon")
        print("Lowest priced Pokemon:", lowest_name.captialize(), "@ $" + format(lowest_price, ",.2f"), "per Pokemon")
        print("Total cost to adopt all Pokemon in the Center: $" + format(counter, ",.2f"))
        print()

    elif lc_s_q == "s":
        name = input("Name of Pokemon to search for: ")
        lc_name = name.lower()
        for i in range(0, len(pokemon_names)):
            if lc_name == pokemon_names[i]:
                print("We have", str(pokemon_amounts[i]), lc_name.capitalize(), "at the Pokemon Center")
                print("It will cost $" + str(format(pokemon_fees[i], ".2f")), "to adopt this Pokemon")
                print(lc_name, "has the following types:", end = "")
                for x in pokemon_types[i]:
                    print(" " + x.capitalize(), end = "")   
                print()
            elif lc_name not in pokemon_names:
                print("We do not have any", lc_name.capitalize(), "at the Pokemon Center")
                break
        print()
        
    elif lc_s_q == "t":
        poke_type = input("Enter Pokemon type: ")
        lc_type = poke_type.lower()
        exist = False
        for type_ in pokemon_types:
            if lc_type in type_:
                exist = True
        if exist:
            print(format("Name", "<14s"), end = "")
            print(format("Amount Available", ">16s"), end = "")
            print(format("Adoption Fee", ">14s"),end = "")
            print(format("Type(s)", ">8s"))
            for i in range(0, len(pokemon_types)):
                if lc_type in pokemon_types[i]:
                    print(format(pokemon_names[i].capitalize(), "<14s"), end = "")
                    print(format(pokemon_amounts[i], ">16"), end = "")
                    print(format(pokemon_fees[i], ">14,.2f"), end = "")
                    for x in pokemon_types[i]:
                        print(" " + x.capitalize(), end = "")
                    print()
        else:
            print("We have no Pokemon of that type at our Pokemon Center")
        print()   

                       
    elif lc_s_q == "l":
        print(format("Name", "<14s"), end = "")
        print(format("Amount Available", ">16s"), end = "")
        print(format("Adoption Fee", ">14s"),end = "")
        print(format("Type(s)", ">8s"))
        for i in range(0, len(pokemon_names)):
            print(format(pokemon_names[i].capitalize(), "<14s"), end = "")
            print(format(pokemon_amounts[i], ">16"), end = "")
            print(format(pokemon_fees[i], ">14,.2f"), end = "")
            for x in pokemon_types[i]:
                print(" " + x.capitalize(), end = "")
            print()
        print()
    elif lc_s_q == "q":
        print("See you next time!")
        break
    else:
        print("Unknown command, please try again\n")


        
    
